class window.Animation
  constructor : (@name, @frames) ->
    @frame = 0
    @frameWait = 32
    @last = Date.now()

  resetFrame = -> @frame = 0

  fps : (fps) ->
    @frameWait = 1000 / fps

  getFrame : ->
    delta = Date.now() - @last
    @last = Date.now()

    delta /= @frameWait
    @frame += delta

    return @frames[(@frame | 0) % @frames.length]

class window.Sprite
  constructor : (@w, @h) ->
    @current = null

  addAnimation : (anim) ->
    @[anim.name] = anim

  getFrame : ->
    return [0, 0] if @current == null
    r = @current.getFrame()
    return [r[0] * @w, r[1] * @h]